feat(currency): Migrate CurrencyFormatter to adopt the new design with generic ValueRepresentation (Decimal) and add short/narrow constructors#8145
Conversation
0e87de5 to
b35fab7
Compare
| try_new: skip, | ||
| try_new_with_buffer_provider, | ||
| try_new_unstable, | ||
| try_new_narrow: skip, |
There was a problem hiding this comment.
why not use the macro-generated version?
There was a problem hiding this comment.
Thanks for the suggestion! We have refactored the constructors to use the macro-generated versions as much as possible (for the buffer and unstable constructors).
However, we still have to skip the compiled constructors (try_new_short/try_new_narrow) in the macro and implement them manually. This is because CurrencyFormatter is a composite formatter that internally instantiates DecimalFormatter (from icu_decimal). Since icu_experimental's local compiled data provider (Baked) only contains experimental keys and does not implement the stable decimal keys, the macro-generated compiled constructors fail to compile due to unsatisfied trait bounds on Baked.
Manually implementing them allows us to initialize DecimalFormatter using its own compiled data, while loading the currency-specific data from icu_experimental's Baked provider. This is the same established pattern used in RelativeTimeFormatter (see relativetime.rs:178).
We have added a TODO comment in the code to re-evaluate and try to use the macro-generated compiled versions once CurrencyFormatter is stabilized and migrated out of experimental.
Additionally, while refactoring, we noticed that try_new_narrow was missing the numbering system fallback loading logic that try_new_short had. We have updated both the compiled and unstable versions of narrow to use the fallback loader, so they are now fully consistent and correct.
|
We have updated this PR to refactor the
This aligns the |
13d73f5 to
8a68189
Compare
|
@robertbastian : Ping |
8a68189 to
8e24118
Compare
8e24118 to
5ffcd74
Compare
e9b611c to
7bea1e7
Compare
…h generic ValueRepresentation (Decimal) and add short/narrow constructors (unicode-org#8145)
7bea1e7 to
3fa1d3d
Compare
) This PR migrates the `LongCurrencyFormatter` functionality into the main `CurrencyFormatter`, building on top of the refactoring in #8145. ## Changelog - Migrated `LongCurrencyFormatter` to `CurrencyFormatter`. - Added `try_new_long` and `try_new_long_unstable` constructors. - Added tests for long currency formatting, including numbering system overrides. - Removed redundant `long_formatter.rs` and `long_format.rs` files.
Migrate the currency formatter based on the design doc:
https://hackmd.io/@younies/number_formatter_4x
Overview
This PR refactors the
CurrencyFormatterinicu_experimentalto align with the proposed design for modular, zero-copy currency formatting (Option 1 in the design doc).Specifically, it introduces the
ValueRepresentationtypestate pattern to partition constructors by capability and representation, starting with the standardDecimalrepresentation, while ensuring consistent locale and numbering system resolution across both short and narrow widths.Changelog
ValueRepresentationtrait andDecimalmarker struct to support typestate-based currency formatting.CurrencyFormatterto be generic overValueRepresentation:pub struct CurrencyFormatter<V: ValueRepresentation>.CurrencyFormatter<Decimal>with newtry_new_shortandtry_new_narrowconstructors (and their unstable/buffer variants), removing the old non-generictry_newconstructors.try_new_narrowto use robust fallback loading, ensuring they correctly support numbering system overrides consistently withtry_new_short.TAG=agy
CONV=0f8e0e91-077a-4704-b63f-0c02f37cbc41